<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Franchise_model extends AppModel {
    var $_primary_key = ADDRESS_ADDRESS_ID;
    var $_tablename = ADDRESS;
    var $_mapping = array(
                           array('id' => ADDRESS_ADDRESS_ID),
                           array('address1' => ADDRESS_LINE1),
                           array('address2' => ADDRESS_LINE2),
                           array('address3' => ADDRESS_LINE3),
                           array('city' => ADDRESS_CITY),
                           array('postcode' => ADDRESS_POSTCODE),
                           array('state' => ADDRESS_STATE),
						   array('phone' => ADDRESS_PHONE),
						   array('mobile' => ADDRESS_MOBILE),
						   array('fax' => ADDRESS_FAX),
						   array('email' => ADDRESS_EMAIL),
						   array('email' => ADDRESS_EMAIL),
                            );
							

    var $_cache = 'franchises_cache';
    var $_sort_field = 'id';
    var $_sort_type = 0;
    public function Franchise_model($id = NULL){
        parent::AppModel($id);
    }
   	function get_franchise($address_id = NULL){
		$this->db->from($this->_tablename.' a');
        $this->db->join(FRANCHISE.' f', 'a.'.ADDRESS_FRANCHISE_ID.' = f.'.FRANCHISE_FRANCHISE_ID);
        $this->db->where('f.'.FRANCHISE_FRANCHISE_ID, $this->admin_id);
		$this->db->where('a.'.ADDRESS_ADDRESS_ID, $address_id);
        $this->_numrow = $this->db->count_all_results();
        if($this->_numrow > 0){
            $this->db->select('a.'.ADDRESS_ADDRESS_ID.' AS id');
            $this->db->select('a.'.ADDRESS_LINE1.' AS address1');
            $this->db->select('a.'.ADDRESS_LINE2.' AS address2');
			$this->db->select('a.'.ADDRESS_LINE3.' AS address3');
            $this->db->select('a.'.ADDRESS_CITY.' AS city');
            $this->db->select('a.'.ADDRESS_POSTCODE.' AS postcode');
			$this->db->select('a.'.ADDRESS_STATE.' AS state');
			$this->db->select('a.'.ADDRESS_PHONE.' AS phone');
			$this->db->select('a.'.ADDRESS_MOBILE.' AS mobile');
			$this->db->select('a.'.ADDRESS_FAX.' AS fax');
			$this->db->select('a.'.ADDRESS_EMAIL.' AS email');
			$this->db->select('f.'.FRANCHISE_NAME.' AS name');
			$this->db->select('f.'.FRANCHISE_FRANCHISEE.' AS franchise');
			$this->db->select('f.'.FRANCHISE_START_DATE.' AS start_date');
			$this->db->select('f.'.FRANCHISE_END_DATE.' AS end_date');
			
            
            $this->db->from($this->_tablename.' a');
        	$this->db->join(FRANCHISE.' f', 'a.'.ADDRESS_FRANCHISE_ID.' = f.'.FRANCHISE_FRANCHISE_ID);
        	$this->db->where('f.'.FRANCHISE_FRANCHISE_ID, $this->admin_id);
			$this->db->where('a.'.ADDRESS_ADDRESS_ID, $address_id);
            return $this->db->get()->result();
        }
        return array();
    }
       
    
}
?>